package com.jiajia.study.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


/**
 * @Title: RabbitConfig
 * @Author zjj
 * @Package com.jiajia.study.config
 * @Date 2024/3/9 14:29
 * @description:
 */

@Configuration
public class RabbitConfig {

    @Bean
    public HeadersExchange headersExchange(){
        return ExchangeBuilder.headersExchange("exchange.headers.a").build();
    }

    @Bean
    public Queue queueA(){
        return QueueBuilder.durable("queue.headers.a").build();
    }
    @Bean
    public Queue queueB(){
        return QueueBuilder.durable("queue.headers.b").build();
    }

    @Bean
    public Binding bindingA(HeadersExchange headersExchange,Queue queueA){
        Map<String,Object> headers = new HashMap<>();
        headers.put("type","m");
        headers.put("status",0);
        return BindingBuilder.bind(queueA).to(headersExchange).whereAll(headers).match();
    }

    @Bean
    public Binding bindingB(HeadersExchange headersExchange,Queue queueB){
        Map<String,Object> headers = new HashMap<>();
        headers.put("type","s");
        headers.put("status",1);
        return BindingBuilder.bind(queueB).to(headersExchange).whereAll(headers).match();
    }

}
